package cn.com.oceansoft.business.szjf.service.impl;

import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.log.persistence.ISysOperLogMapper;
import cn.com.oceansoft.business.szjf.entity.*;
import cn.com.oceansoft.business.szjf.persistence.IExpertMapper;
import cn.com.oceansoft.business.szjf.persistence.IPszlMapper;
import cn.com.oceansoft.business.szjf.service.IPsshService;
import cn.com.oceansoft.nos.common.util.web.PageUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.log4j.LogManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/26.
 */
@Service
public class PsshServiceImpl implements IPsshService {

    @Resource
    private IPszlMapper pszlMapper;
    @Resource
    private ISysOperLogMapper sysOperLogMapper;
    @Resource
    private IExpertMapper expertMapper;

    @Override
    public List<Regional> getRegional() {
        return pszlMapper.getRegional();
    }

    @Override
    public Pager<Pssh> showFirstReview(Query query) {
        PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
        Page<Pssh> page = (Page<Pssh>) pszlMapper.showFirstReview(query);
        return PageUtil.page2pager(page, query);
    }

    @Override
    public Pssh getDetailByPrjNo(String guid) {
        return pszlMapper.getDetailByPrjNo(guid);
    }

    @Override
    public List<Position> getDistributePosition(String type) {
        return pszlMapper.getDistributePosition(type);
    }

    @Override
    public void giveOut(String paguid,String distributerole,String userguid,String distributeName) {
        pszlMapper.giveOut(paguid,distributerole);
        CheckInfo info = new CheckInfo();
        info.setPaguid(paguid);
        info.setCheckresult("初审通过");
        info.setComments("初审通过，分发至"+distributeName);
        info.setCheckstep("评审初审");
        info.setCheckuser(userguid);//当前用户guid
        info.setCheckdate(new Date());
        info.setReturnnode("");
        expertMapper.insertCheckInfo(info);

        Pssh s = pszlMapper.getDetailByPrjNo(paguid);
        Logmanage log = new Logmanage();
        log.setUserguid(userguid);
        log.setLogmodule("评审资料初审");
        log.setLogpage("_Distribute");
        log.setLogtype("记录日志");
        log.setLogcontent(s.getProjectno()+"项目 评审资料初审 分发成功");
        log.setOperationtme(new Date());
        log.setIsdelete("0");
        sysOperLogMapper.insertLog(log);
    }

    @Override
    public void pass(String paguid,String userguid) {
        pszlMapper.pass(paguid);
        CheckInfo info = new CheckInfo();
        info.setPaguid(paguid);
        info.setCheckresult("受理通过");
        info.setComments("受理通过，流程至抽取评审专家");
        info.setCheckstep("评审受理");
        info.setCheckuser(userguid);//当前用户guid
        info.setCheckdate(new Date());
        info.setReturnnode("");
        expertMapper.insertCheckInfo(info);

        Pssh s = pszlMapper.getDetailByPrjNo(paguid);
        Logmanage log = new Logmanage();
        log.setUserguid(userguid);
        log.setLogmodule("评审资料受理");
        log.setLogpage("_SlPass");
        log.setLogtype("记录日志");
        log.setLogcontent(s.getProjectno()+"项目 评审资料受理 已通过");
        log.setOperationtme(new Date());
        log.setIsdelete("0");
        sysOperLogMapper.insertLog(log);
    }

    @Override
    public void updateObjByGuid(Pssh prj) {
        pszlMapper.updateObjByGuid(prj);
    }

}
